#include "configurationdialog.h"
#include "ui_configurationdialog.h"
#include "../logic/thememanager.h"

#include <QCheckBox>
#include <QtDebug>

ConfigurationDialog::ConfigurationDialog( PluginHandler * pluginHandler, ThemeManager * themeManager, QWidget *parent) :
    QDialog(parent),
    m_ui( new Ui::configurationdialog ) {
    m_ui->setupUi(this);
    this->listPlugins( pluginHandler );
    this->listThemes( themeManager );
}

ConfigurationDialog::~ConfigurationDialog() {
    delete m_ui;
}

void ConfigurationDialog::listPlugins( PluginHandler * pluginHandler ) {
    m_ui->pluginLayout->setSpacing( 5 );
    m_ui->pluginLayout->setAlignment( Qt::AlignTop );

    // display checkbox for each plugin
    foreach ( WhalePlugin * plugin, pluginHandler->plugins() ) {
        QCheckBox * checkBox = new QCheckBox( plugin->Name );
        if ( plugin->Enabled ) {
            checkBox->setCheckState( Qt::Checked );
        }
        else {
            checkBox->setCheckState( Qt::Unchecked );
        }
        m_ui->pluginLayout->addWidget( checkBox );

        connect( checkBox, SIGNAL( stateChanged( int ) ), plugin, SLOT( setEnabled( int ) ) );
    }
}

void ConfigurationDialog::listThemes( ThemeManager * themeManager ) {
    this->m_ui->themeBox->addItems( themeManager->themes() );
    this->m_ui->themeBox->setCurrentIndex( themeManager->themes().indexOf( themeManager->activeTheme() ) );
    connect( this->m_ui->themeBox, SIGNAL( activated( const QString & ) ), themeManager, SLOT( select( const QString & ) ) );
}
